var t, e = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), a = require("../../../@babel/runtime/helpers/asyncToGenerator"), n = require("../../../utils/DPagination").default, o = require("../common").getProjectNameLang, r = require("../../../mybehaviors/location/location"), i = getApp(), s = new n("nearbyProjects"), c = null, g = o();

Page({
    behaviors: [ r ],
    data: {
        carousels: [],
        recommendProjects: [],
        categories: [],
        category_10: [],
        nearbyProjects: [],
        projectNameLang: o(),
        showLocation: !1,
        Height: 0,
        LastHeight: 0,
        paramsData:{placeholder:'搜索',color:'#333',color2:'#999',bgcolor:'rgb(242,242,242)'}
    },
    onLoad: (t = a(e.default.mark(function t(a) {
        var n = this;
        return e.default.wrap(function(t) {
            for (;;) switch (t.prev = t.next) {
              case 0:
                this._getLocation(function(t, e) {
                    c = {
                        point: e
                    }, n.setData({
                        showLocation: !0
                    }), wx.setNavigationBarTitle({
                        title: g + "列表"
                    }), s.bind(n), n.getPageData(), n.getNearbyProjects();
                });

              case 1:
              case "end":
                return t.stop();
            }
        }, t, this);
    })), function(e) {
        return t.apply(this, arguments);
    }),
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.getNearbyProjects();
    },
    onShareAppMessage: function() {},
    imgHeight: function(t) {
        var e = wx.getSystemInfoSync().windowWidth * t.detail.height / t.detail.width + "px";
        parseInt(e) > this.data.LastHeight && (this.setData({
            Height: e
        }), this.data.LastHeight = parseInt(e));
    },
    getPageData: function() {
        var t = this, e = i.getNetAddresss("plugin.store-projects.frontend.index.get-data"), a = i.qqMapTransBMap(parseFloat(c.point.lng), parseFloat(c.point.lat));
        i._getNetWork({
            url: e,
            data: {
                lng: a.lng,
                lat: a.lat
            },
            success: function(e) {
                var a = e.data.data;
                t.setData({
                    carousels: a.carousels,
                    recommendProjects: a.projects,
                    categories: a.project_category_list || []
                });
                var n = t.chunk(t.data.categories, 10);
                t.setData({
                    category_10: n
                });
            }
        });
    },
    chunk: function(t, e) {
        for (var a = [], n = 0, o = t.length; n < o; n += e) a.push(t.slice(n, n + e));
        return a;
    },
    goCategory: function(t) {
        var e = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageH/project_verification/CategoryProjectList/CategoryProjectList?category_id=" + e
        });
    },
    getNearbyProjects: function() {
        if (!s.finished && !s.loading) {
            wx.showLoading(), s.loading = !0;
            var t = i.getNetAddresss("plugin.store-projects.frontend.project.get-list"), e = i.qqMapTransBMap(parseFloat(c.point.lng), parseFloat(c.point.lat));
            i._getNetWork({
                url: t,
                data: {
                    lng: e.lng,
                    lat: e.lat,
                    page: s.loadPage
                },
                success: function(t) {
                    var e = t.data.data;
                    wx.hideLoading(), (e.last_page == e.current_page || e.data.length < e.per_page) && (s.finished = !0), 
                    s.push(e.data), s.loading = !1;
                },
                fail: function() {
                    wx.hideLoading(), s.loading = !1;
                }
            });
        }
    }
});